package com.jz.yanshe.ui;

import android.content.Context;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import jz.com.feierman.R;

import com.jz.yanshe.base.BaseActivity;
import com.jz.yanshe.ui.fragment.OrderListFragment;

/**
 * Created by Administrator on 2018/2/28.
 */

public class MyOrderActivity extends BaseActivity{

    @BindView(R.id.timeline_tablayout)
    TabLayout mTabLayout;
    @BindView(R.id.timeline_viewpager)
    ViewPager mViewPager;

    private int type;

    @Override
    protected void initViews() {
        mViewPager.setAdapter(new OrderFragmentAdapter(this, getSupportFragmentManager()));
        mTabLayout.setupWithViewPager(mViewPager);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        mViewPager.setCurrentItem(type);
        mTabLayout.getTabAt(type).select();
    }

    @Override
    protected void initData() {
        type = getIntent().getExtras().getInt("id");
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_my_order;
    }

    class OrderFragmentAdapter extends FragmentPagerAdapter {
        private static final int PAGE_COUNT = 6;

        private Context mContext;

        public OrderFragmentAdapter(Context context, FragmentManager fm) {
            super(fm);
            this.mContext = context;
        }

        @Override
        public Fragment getItem(int position) {
            String type;
            switch (position) {
                case 0:
                    type = "0";
                    break;
                case 1:
                    type = "1";
                    break;
                case 2:
                    type = "4";
                    break;
                case 3:
                    type = "5";
                    break;
                case 4:
                    type = "6";
                    break;
                case 5:
                    type = "11";
                    break;
                default:
                    type = "7";
                    break;
            }
            return OrderListFragment.newInstance(type);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "全部";
                case 1:
                    return "待付款";
                case 2:
                    return "待发货";
                case 3:
                    return "待收货";
                case 4:
                    return "售后";
                case 5:
                    return "已完成";
                default:
                    return "售后";
            }
        }

    }


}
